package com.websocket;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.Collections;

import lombok.SneakyThrows;
import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.handshake.ServerHandshake;
import org.java_websocket.server.WebSocketServer;


/**
 * @program: mpf-eventbridge
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2022-11-28 16:14
 **/
public class TestClient extends WebSocketClient{

    private static final long serialVersionUID = -6056260699202978657L;

    private WebSocketClient cc;

    public TestClient(String url) {
        super(URI.create(url));
    }


    public static void main(String[] args) throws InterruptedException {
        TestClient testClient = new TestClient("ws://127.0.0.1:8081/websocket");
        testClient.connect();

        Thread.sleep(3000L);
        testClient.send("123456");
    }

    @Override
    public void onOpen(ServerHandshake serverHandshake) {
        System.out.println("TestClient onOpen");
    }

    @Override
    public void onMessage(String s) {
        System.out.println("TestClient onMessage:" + s);
    }

    @Override
    public void onClose(int i, String s, boolean b) {
        System.out.println("TestClient onClose");
    }

    @Override
    public void onError(Exception e) {
        System.out.println("TestClient onError");
    }
}